package com.DCapps.sendakiss.helper;

import java.util.ArrayList;

import com.DCapps.sendakiss.Friend;
import com.google.i18n.phonenumbers.PhoneNumberUtil;
import com.google.i18n.phonenumbers.PhoneNumberUtil.PhoneNumberFormat;
import com.google.i18n.phonenumbers.Phonenumber;
import com.google.i18n.phonenumbers.Phonenumber.PhoneNumber;

import android.content.Context;
import android.database.Cursor;
import android.provider.ContactsContract;

public class Helper {
	
	public static ArrayList<String> getAllPhoneNumbers(Context c)
	{
		ArrayList<String> nbrs = new ArrayList<String>();
		PhoneNumberUtil phoneUtil = PhoneNumberUtil.getInstance();
		
		Cursor phones = c.getContentResolver().query(ContactsContract.CommonDataKinds.Phone.CONTENT_URI, null,null,null, null);
		while (phones.moveToNext())
		{
		  //String name=phones.getString(phones.getColumnIndex(ContactsContract.CommonDataKinds.Phone.DISPLAY_NAME));
		  String phoneNumber = phones.getString(phones.getColumnIndex(ContactsContract.CommonDataKinds.Phone.NUMBER));
		  if (phoneNumber != null && phoneNumber.compareTo("") != 0)
		  {
			  nbrs.add(phoneNumber);
		  }
		}
		phones.close();
		
		
		
		return nbrs;
	}
	
	public static ArrayList<Friend> getFriends(ArrayList<String> numbers, Context c)
	{
		ArrayList<Friend> tempFriends = new ArrayList<Friend>();
		
		
		Cursor phones = c.getContentResolver().query(ContactsContract.CommonDataKinds.Phone.CONTENT_URI, null,null,null, null);
		while (phones.moveToNext())
		{
		  String name=phones.getString(phones.getColumnIndex(ContactsContract.CommonDataKinds.Phone.DISPLAY_NAME));
		  String phoneNumber = phones.getString(phones.getColumnIndex(ContactsContract.CommonDataKinds.Phone.NUMBER));
		  
		  if (numbers.contains(phoneNumber))
		  {
			  Friend f = new Friend();
			  f.setName(name);
			  f.setPhoneNumber(phoneNumber);
			  
			  tempFriends.add(f);
			  
		  }
		}
		phones.close();
		
		
		return tempFriends;
	}
	

}
